function parseURL(url) {
	const regex = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/;
	const result = regex.exec(url);
	return {
		protocol: result[1],
		host: result[2],
		path: result[3],
		query: result[4],
		fragment: result[5]
	};
}

function parseUrlQuery(url) {
	const params = {};
	if (url.indexOf('?') > -1) {
		var queryString = url.split('?')[1];
	} else {
		var queryString = url
	}
	if (queryString) {
		const pairs = queryString.split('&');
		pairs.forEach(pair => {
			const [key, value] = pair.split('=');
			params[key] = decodeURIComponent(value);
		});
	}
	return params;
}

  function get(a, key, defaultValue = '') {

      if('object' !== typeof a){
          return defaultValue;
      }
      if ('number' === typeof key) {
          return a[key] === undefined ? defaultValue : a[key];
      }
      let dotIdx = key.indexOf('.')
      if (dotIdx === -1) {
          return a[key] === undefined ? defaultValue : a[key];
      }
      let k1 = key.substring(0, dotIdx);
      if (a[k1] === undefined) {
          return defaultValue;
      }
      return arr.get(a[k1], key.substring(dotIdx + 1), defaultValue)
  }

export default {
	get,
	parseURL,
	parseUrlQuery
}